home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / thor / fse / style.fse < prev    next >
Text File  |  1996-11-10  |  3KB  |  107 lines

  1. /* Style.fse by Troels Walsted Hansen
  2. ** $VER: Style.fse v2.00ß (30.11.94)
  3. **
  4. ** Purpose: Apply style to word.
  5. **
  6. ** History:
  7. ** Style.fse v2.00ß (30.11.94)
  8. **  · rewritten completely
  9. **  · determines whether word contains illegal characters
  10. **  · works as a toggle - run once to place one set of stylechars,
  11. **    run again to remove them
  12. **  · doesn't handle characters at the left or right of a word correctly :(
  13. **    e.g. '>>hello,' becomes '*>>hello,*' instead of '>>*hello*,'
  14.  
  15. */
  16.  
  17. options results
  18. parse arg portname stylechar
  19. address(portname)
  20.  
  21. XPOS
  22. cur = result
  23.  
  24. GETLINE
  25. line = result
  26.  
  27. /* If the current character is non-alphabetic, then start one character
  28. ** over to the left.  This allows the cursor to be immediately after
  29. ** the key word (say on a space or bracket.)
  30. */
  31.  
  32. /* find word */
  33.  
  34. totalwnumber = words(line)
  35. if(totalwnumber < 1) then call QuitWithError('There''s no text on this line.')
  36.  
  37. do i=1 to totalwnumber
  38.     if(cur < wordindex(line, i)) then break
  39. end
  40.  
  41. /* some useful variables for later on */
  42.  
  43. styleword = word(line, i-1)
  44. wordnumber = i-1
  45. wordlength = length(styleword)
  46. wordstart = wordindex(line, wordnumber)
  47.  
  48. /* determine whether some other character than `: ; . , ! ) ( " ? >'
  49. ** has been placed at the beginning or end of the line
  50. */
  51.  
  52. leftchar = left(styleword, 1)
  53. rightchar = right(styleword, 1)
  54.  
  55. if(translate(leftchar, '..................................................................................', '*/_#:;.,!)("?>qwertyuiopasdfghjklzxcvbnmøæåQWERTYUIOPASDFGHJKLZXCVBNMØÆÅ1234567890') ~= '.') then
  56.     call QuitWithError('Leftmost character is illegal.')
  57.  
  58. if(translate(rightchar, '..................................................................................', '*/_#:;.,!)("?>qwertyuiopasdfghjklzxcvbnmøæåQWERTYUIOPASDFGHJKLZXCVBNMØÆÅ1234567890') ~= '.') then
  59.     call QuitWithError('Rightmost character is illegal.')
  60.  
  61. /* if the current stylechars are already in place, remove them and exit */
  62.  
  63. if(leftchar = stylechar & rightchar = stylechar & wordlength > 2) then
  64. do
  65.     SETPOS X wordstart
  66.     INSERTINPUT '7F'x
  67.  
  68.     SETPOS X wordstart+wordlength-2
  69.     INSERTINPUT '7F'x
  70.  
  71.     exit
  72. end
  73.  
  74. /* if other stylechars then the current ones are present, ignore them */
  75.  
  76. if(leftchar = '*' | leftchar = '/' | leftchar = '_' | leftchar = '#' & leftchar = rightchar) then
  77.     fixedstyleword = strip(styleword, B, '*/_#')
  78. else
  79.     fixedstyleword = styleword
  80.  
  81. translated = translate(fixedstyleword, '......................................................................................................', '->!:;@.,"()[]?''\®©þ¡ßð×¹²³¢¼½¾ÞУÇç¿qwertyuiopasdfghjklzxcvbnmøæåQWERTYUIOPASDFGHJKLZXCVBNMØÆÅ1234567890')
  82.  
  83. dotword = ''
  84. do length(fixedstyleword)
  85.     dotword = dotword || '.'
  86. end
  87.  
  88. if(translated ~= dotword) then call QuitWithError('Word contain(s) illegal character(s).')
  89.  
  90. /* place stylechars */
  91.  
  92. SETPOS X wordstart
  93. INSERTSTRING strip(stylechar)
  94.  
  95. SETPOS X wordstart+wordlength+1
  96. INSERTSTRING strip(stylechar)
  97.  
  98. SETPOS wordstart+wordlength+2
  99.  
  100. exit
  101.  
  102. QuitWithError:
  103.     parse arg errorstring
  104.     REQUESTNOTIFY TEXT '"'errorstring'"' BT '"_Ok"'
  105.     exit
  106. end
  107.